var app = getApp();
const Zan = require('../../../dist/index');
const config = require('./config');
var Const = require('./../../../utils/const');

Page(Object.assign({}, Zan.TopTips, Zan.Field, {

	data: {
		config
	},

	onLoad: function (options) {

	},

	onReady: function () {

	},

	onShow: function () {

	},

	onHide: function () {

	},

	handleZanFieldChange(e) {
		const {componentId, detail} = e;
	},

	handleZanFieldFocus(e) {
		const {componentId, detail} = e;
	},

	handleZanFieldBlur(e) {
		const {componentId, detail} = e;
	},

	idcardSubmit(e) {
		var that = this;
		var name = e.detail.value['idcard:name'];
		var idcard = e.detail.value['idcard:idcard'];

		//name check
		if (name != null && name != undefined && name != '') {
			if (name.length < 2) {
				that.showZanTopTips('请输入真实姓名', {type: 'error'});
				return false;
			}
		} else {
			that.showZanTopTips('请输入真实姓名', {type: 'error'});
			return false;
		}

		//idcard check
		if (idcard != null && idcard != undefined && idcard != '') {
			if (!(/(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test(idcard))) {
				that.showZanTopTips('请输入正确身份证号', {type: 'error'});
				return false;
			}
		} else {
			that.showZanTopTips('请输入身份证号', {type: 'error'});
			return false;
		}

		var _data = {
			name: name,
			idcard: idcard,
			ticket: app.data.token
		}

		app.battery.common('member/idcard', _data).then(function (data) {
			if (data) {
				wx.navigateBack({
					delta: 1
				})
			} else {
				that.showZanTopTips("认证失败", {type: 'error'});
			}
		}).catch(function (e) {
			that.showZanTopTips(e.message, {type: 'error'});
		});
	}
}));